package deweb.cimaplanning.beans;

import java.util.ArrayList;

import deweb.cimaplanning.misc;
import deweb.cimaplanning.dao.POPlantCostDao;

public class POPlantCostsBean {
	protected int versionId;
	
	protected boolean successful;
	protected String errorMsg;
	
	private POPlantCostDao dao = null;
	
	public POPlantCostsBean(){
		dao = new POPlantCostDao();
	}
	
	public ArrayList browse(){
		return browse(0, misc.ALL, true);
	}

	public ArrayList browse(int versionId){
		return browse(versionId, misc.ALL, true);
	}
	
	public ArrayList browse(int versionId, String filtersChain, boolean in){
		ArrayList results	= null;
		String sql			= "";
		
		if (versionId > 0)
			sql = "	pov.version_id = " + versionId + " ";
		
		if (filtersChain.equals(misc.ALL))
			sql += "		AND ce.short_name NOT IN ('" + misc.USD_PER_TON + "', '" + misc.LOSS_FUTURES + "') ";
		else {
			sql += "		AND ce.short_name " + (in ? "" : "NOT") + " IN ('" + filtersChain + "')  ";
		}
		
		try {
			results = dao.getArray(sql);
			
			successful	= true;
			errorMsg	= "";
		} catch (Exception e) {
			successful	= false;
			errorMsg	= e.getMessage();
			e.printStackTrace();
			return null;
		}
		
		return results;
	}
	
	/**
	 * @return the successful
	 */
	public boolean isSuccessful() {
		return successful;
	}

	/**
	 * @return the errorMsg
	 */
	public String getErrorMsg() {
		return errorMsg;
	}
}
